/*
 Example 5.2
 Using a 7-segment display with the 74HC595 shift register
 CC by-sa 3.0
 http://tronixstuff.wordpress.com
 
 */

int latchpin = 8; // connect to pin 12 on the '595
int clockpin = 12; // connect to pin 11 on the '595
int datapin = 11; // connect to pin 14 on the '595

int segdisp[10] = {63,6,91,79,102,109,125,7,127,111 };

void setup()
{
  pinMode(latchpin, OUTPUT);
  pinMode(clockpin, OUTPUT);
  pinMode(datapin, OUTPUT);
}
void loop()
{

  digitalWrite(latchpin, LOW);
  shiftOut(datapin, clockpin, MSBFIRST, 0); // clears the display
  digitalWrite(latchpin, HIGH);
  delay(1000);

  for (int loopy=0; loopy<10; loopy++)
  // counts from 0 to 9, using the values in the array segdisp[]
  // whose values correspond to the binary outputs 0~9
  {
    digitalWrite(latchpin, LOW);
    shiftOut(datapin, clockpin, MSBFIRST, segdisp[loopy]+128);
    digitalWrite(latchpin, HIGH);
    delay(200);
  }

  digitalWrite(latchpin, LOW);
  shiftOut(datapin, clockpin, MSBFIRST, 0); // clear the display
  digitalWrite(latchpin, HIGH);
  delay(1000);

  for (int loopy=9; loopy>-1; loopy--)
  {
  // counts from 9 to 0, using the values in the array segdisp[]
  // whose values correspond to the binary outputs 0~9
    digitalWrite(latchpin, LOW);
    shiftOut(datapin, clockpin, MSBFIRST, segdisp[loopy]+128);
    digitalWrite(latchpin, HIGH);
    delay(200);
  }

  digitalWrite(latchpin, LOW);
  shiftOut(datapin, clockpin, MSBFIRST, 0); // clear the display
  digitalWrite(latchpin, HIGH);
  delay(1000);
  
  digitalWrite(latchpin, LOW);
  shiftOut(datapin, clockpin, MSBFIRST, 128); // light the decimal point
  digitalWrite(latchpin, HIGH);
  delay(1000);
  
  digitalWrite(latchpin, LOW); // clear the display
  shiftOut(datapin, clockpin, MSBFIRST, 0);
  digitalWrite(latchpin, HIGH);
  delay(1000);

  digitalWrite(latchpin, LOW);
  shiftOut(datapin, clockpin, MSBFIRST, 255); // light up all segments
  digitalWrite(latchpin, HIGH);
  delay(1000);
  digitalWrite(latchpin, LOW);
  shiftOut(datapin, clockpin, MSBFIRST, 0); // clear the display
  digitalWrite(latchpin, HIGH);
  delay(1000);
}




